package com.zisu.aradvertising.controller;


import com.zisu.aradvertising.pojo.Advertiser;
import com.zisu.aradvertising.pojo.Result;
import com.zisu.aradvertising.service.AdvertiserService;
import lombok.Data;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/advertiser")
public class AdvertiserConrtoller {
    @Resource
    private AdvertiserService advertiserService;
    //登录控制
    @PostMapping("/login")
    public Result<Advertiser> loginController(@RequestParam String aemail, @RequestParam String apassword) {
        Advertiser advertiser = advertiserService.loginService(aemail, apassword);
        if (advertiser != null) {
            return Result.success(advertiser, "登录成功!");
        } else{
            return  Result.error("123","账号密码错误!");
        }
    }
    //注册控制
    @PostMapping("/register")
    public Result<Advertiser> registController(@RequestBody Advertiser newAdvertiser)
    {
        Advertiser advertiser =advertiserService.registService(newAdvertiser);
        if (advertiser != null) {
            return Result.success(advertiser, "注册成功！");
        } else {
            return Result.error("456", "该邮箱已被注册过！");
        }
    }

    //修改密码
    @PostMapping("/edit")
    public Result<Advertiser> editController(@RequestParam String aemail, @RequestParam String apassword)
    {
        Advertiser advertiser =advertiserService.updatepasswordService(aemail,apassword);
        if (advertiser != null) {
            return Result.success(advertiser, "修改密码成功");
        } else {
            return Result.error("456", "邮箱错误！");
        }
    }
    //返回所有广告商创作者
    @PostMapping("/findall")
    public Result<List<Advertiser>> findallConroller() {
        List<Advertiser> list = advertiserService.findallService();
        if (list != null) {
            return Result.success(list, "查询成功");
        } else {
            return Result.error("123", "查询失败!");
        }
    }

    //返回一个广告位下所有正在合作的广告商
    @PostMapping("/findallbyapid")
    public Result<List<Advertiser>> findallbyapidConroller(@RequestParam int apid) {
        List<Advertiser> list = advertiserService.findallbyapidService(apid);
        if (list != null) {
            return Result.success(list, "查询成功");
        } else {
            return Result.error("123", "查询失败!");
        }
    }

    //返回一个合作号下的广告商
    @PostMapping("/findbycoid")
    public Result<Advertiser> findbycoidController(@RequestParam int coid){
        Advertiser advertiser=advertiserService.findbycoidService(coid);
        if (advertiser != null) {
            return Result.success(advertiser, "查询广告商成功");
        } else {
            return Result.error("123", "查询广告商失败!");
        }

    }
    //根据广告商的id返回该广告商的所有信息
    @PostMapping("/findbyaid")
    public Result<Advertiser> findbyaidController(@RequestParam int aid){
        Advertiser advertiser=advertiserService.findbyaidService(aid);
        if (advertiser != null) {
            return Result.success(advertiser, "查询广告商成功");
        } else {
            return Result.error("123", "查询广告商失败!");
        }
    }
    //根据广告商的id返回该广告商的所有信息
    @PostMapping("/wx")
    public int wxdemo(){
        return 0;
    }
}











